package Exercise02;

import java.math.BigDecimal;

public class Mean {

    public static void main(String[] args) {

        double[] arr = {0.1, 0.2, 2.1, 3.2, 5.56, 7.21};
        BigDecimal sum = new BigDecimal(String.valueOf(arr[0]));
        for (int i = 0; i < arr.length; i++) {

            BigDecimal b = new BigDecimal(String.valueOf(arr[i]));
            sum = sum.add(b);
        }
        System.out.println("元素和" + sum);
        System.out.println("四舍五入后的平均值" + sum.divide(new BigDecimal(String.valueOf(arr.length)), 2, BigDecimal.ROUND_HALF_UP));


    }
}
